<template>
    <div class="detail">
        <div class="nav" :style="{'opacity':opacity}">{{movie.title}}</div>
        <div class="img">
           <img class="return" src="@/assets/return.png" alt="" @click="goBack">
           <img class="pic" :src="movie.pic" alt="">
        </div>
        <div class="content">
            <div class="header">
                <div class="title">{{movie.title}}</div>
                <div class="rating"><span>{{movie.rating}}</span>分</div>
            </div>
            <div class="info">
                <div class="type">{{movie.type}}</div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                movie:'',
                opacity:0
            }
        },
        mounted() {
            var id = this.$route.query.id
            this.getHttp(id)
            window.addEventListener('scroll',this.handleScroll)
        },
        methods: {
            getHttp(id){
                this.$http.get(`http://47.108.197.28:4000/api/movieDetail?id=${id}`).then(res=>{
                    res.data.res.forEach(item=>{
                        item.type=item.labels.join('|')
                    })
                    this.movie = res.data.res[0]
                })
            },
            handleScroll(){
                var scrollTop = document.documentElement.scrollTop
                var opacity = scrollTop/100
                if(opacity>1){
                    opacity=1
                }
                this.opacity = opacity
            },
            goBack(){
                this.$router.go(-1)
            }
        },
        destroyed(){
            window.removeEventListener('scroll',this.handleScroll)
        }
    }
</script>

<style scoped>
.detail{
    height: 1000px;
}
.img{
    height: 55vw;
    overflow: hidden;
    position: relative;
}
.img img{
    position: absolute;
}
.return{
    width:10vw;
    z-index: 2;
    margin:1vw;
}
.pic{
    width: 100%;
    top: -30%;
}
.content{
    padding:5vw;
}
.title{
    font-size: 6vw;
    float: left;
}
.header{
    overflow: hidden;
}
.rating{
    float: right;
    color: rgb(223, 163, 52);
}
.rating span{
    font-size: 7vw;
    font-style: italic
}
.type{
    font-size: 4.5vw;
    color: #666;
}
.info{
    margin-top: 3vw;
}
.nav{
    position: fixed;
    top: 0;
    width: 100%;
    height: 14vw;
    line-height: 14vw;
    text-align: center;
    font-size: 5.3vw;
    z-index: 1;
    background-color: white;
}
</style>